<form enctype="multipart/form-data" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
  <input type="hidden" name="MAX_FILE_SIZE" value="104857600"/>
  上传文件:<input type="file" name="upload_file" size="50"/>
  <input type="submit" name="submit" value="上传"/>
</form>
<?php
if(isset($_POST['submit'])){
    switch($_FILES['upload_file']['error']){
	  case  UPLOAD_ERR_INI_SIZE:
	    echo '<script>alert("文件大小超过了服务器限制！");</script>';
	    break;
	  case  UPLOAD_ERR_FORM_SIZE:
	    echo '<script>alert("文件大小超过了浏览器限制！");</script>';
	    break;
	  case  UPLOAD_ERR_PARTIAL:
	    echo '<script>alert("只有部分文件被上传！");</script>';
	    break;
	  case  UPLOAD_ERR_NO_FILE:
	    echo '<script>alert("没有文件被上传！");</script>';
	    break;
	  case  UPLOAD_ERR_NO_TMP_DIR:
	    echo '<script>alert("找不到临时文件！");</script>';
	    break;
	  case  UPLOAD_ERR_CANT_WRITE:
	    echo '<script>alert("文件写入失败！");</script>';
	    break;
	  case  UPLOAD_ERR_OK:
	    $upload_dir='./'.iconv("UTF-8","gb2312",$_FILES['upload_file']['name']);
	    if(file_exists($upload_dir)){
	        echo '<script>alert("已经存在同名文件！");</script>';
	        }
	        else
	       {
	        if(move_uploaded_file($_FILES['upload_file']['tmp_name'],$upload_dir))
	        {
	        echo '<script>alert("文件上传成功！");</script>';
	        }
	        else
	        {
	        echo '<script>alert("文件上传失败！");</script>';
	        }
	       }
	       break;
	    }
	}
 ?>